home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 137UJ9T (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.8 KB  |  63 lines

  1. package com.ibm.uvm.abt.edit;
  2.  
  3. import java.awt.Rectangle;
  4. import java.beans.PropertyEditorSupport;
  5. import java.util.ResourceBundle;
  6.  
  7. public class RectanglePropertyEditor extends PropertyEditorSupport {
  8.    private static ResourceBundle resabtedit = ResourceBundle.getBundle("com/ibm/uvm/abt/edit/abtedit");
  9.  
  10.    public String getAsText() {
  11.       if (((PropertyEditorSupport)this).getValue() instanceof String) {
  12.          return (String)((PropertyEditorSupport)this).getValue();
  13.       } else if (((PropertyEditorSupport)this).getValue() == null) {
  14.          return "";
  15.       } else {
  16.          Rectangle rect = (Rectangle)((PropertyEditorSupport)this).getValue();
  17.          return "" + rect.x + ", " + rect.y + ", " + rect.width + ", " + rect.height;
  18.       }
  19.    }
  20.  
  21.    public String getJavaInitializationString() {
  22.       Rectangle rect = (Rectangle)((PropertyEditorSupport)this).getValue();
  23.       return rect == null ? "new java.awt.Rectangle(0,0,0,0)" : "new java.awt.Rectangle(" + rect.x + ", " + rect.y + ", " + rect.width + ", " + rect.height + ")";
  24.    }
  25.  
  26.    private Rectangle parseForRectangle(String text) throws Exception, NumberFormatException {
  27.       int x = text.indexOf(",");
  28.       if (x < 0) {
  29.          throw new Exception(resabtedit.getString("Rect_num_must_be_sep"));
  30.       } else {
  31.          String xText = text.substring(0, x);
  32.          String remains = text.substring(x + ",".length());
  33.          int y = remains.indexOf(",");
  34.          if (y < 0) {
  35.             throw new Exception(resabtedit.getString("Rect_num_must_be_sep"));
  36.          } else {
  37.             String yText = remains.substring(0, y);
  38.             remains = remains.substring(y + ",".length());
  39.             int w = remains.indexOf(",");
  40.             if (w < 0) {
  41.                throw new Exception(resabtedit.getString("Rect_num_must_be_sep"));
  42.             } else {
  43.                String wText = remains.substring(0, w);
  44.                String hText = remains.substring(w + ",".length());
  45.                return new Rectangle(Integer.valueOf(xText.trim()), Integer.valueOf(yText.trim()), Integer.valueOf(wText.trim()), Integer.valueOf(hText.trim()));
  46.             }
  47.          }
  48.       }
  49.    }
  50.  
  51.    public void setAsText(String text) throws IllegalArgumentException {
  52.       if (text instanceof String) {
  53.          try {
  54.             ((PropertyEditorSupport)this).setValue(this.parseForRectangle(text));
  55.          } catch (Exception var3) {
  56.             throw new IllegalArgumentException(((Throwable)var3).getMessage());
  57.          }
  58.       } else {
  59.          throw new IllegalArgumentException(text);
  60.       }
  61.    }
  62. }
  63.